package exp4;

import java.util.Random;

public class Exp4_1 {
	public static void main(String[] args) {
		Random random = new Random();
		int[] a = new int[10 + 1];
		int temp;
		boolean exchange;
		System.out.println("随机生成的数组：");
		for (int i = 1; i < a.length; i++) {
			a[i] = random.nextInt(100);
			System.out.printf("%-4d", a[i]);
		}
		for (int i = 1; i < a.length - 1; i++) {
			exchange = false;
			for (int j = 1; j < a.length - i; j++) {
				if (a[j] > a[j + 1]) {
					temp = a[j];
					a[j] = a[j + 1];
					a[j + 1] = temp;
					exchange = true;
				}
			}
			if (exchange == false) {
				break;
			}
		}
		System.out.print("\n最大值为：");
		System.out.println(a[10]);
		System.out.println("排序后：");
		for (int i = 1; i < a.length; i++) {
			System.out.printf("%-4d", a[i]);
		}
		for (int i = 1, j = 10; i <= j; i++, j--) {
			temp = a[i];
			a[i] = a[j];
			a[j] = temp;
		}
		System.out.println();
		System.out.println("翻转后：");
		for (int i = 1; i < a.length; i++) {
			System.out.printf("%-4d", a[i]);
		}
	}
}
